package MyPackage;
import java.io.File;
import java.util.Scanner;

public class Control {
	
	public String dir="C:\\";
	
	public Model myModel=new Model();

public String prompt(){
String result="ERROR";
File f=new File(dir);
if(!f.exists()) System.out.println("Prompt:Not found directory "+f.toString());
else{
	if(f.isDirectory()){
		System.out.print(dir+">");
		Scanner inp=new Scanner(System.in);
		String command;
		command=inp.nextLine();
		result=parser(command);
	}
	else{
		System.out.println("Error. It is not directory "+f.toString());
	}
}
return result;
}

public String parser(String command){	
	
		String strResult="";
		boolean result=false;
		String[] arrayCommand=command.split(" ");
		myModel.numArg=arrayCommand.length-1;
		if(myModel.numArg>0) myModel.arg1=arrayCommand[1];
		if(myModel.numArg>1) myModel.arg2=arrayCommand[2];
		
try{		
		switch (Command.myCommand.valueOf(arrayCommand[0])) {
		
        case exit:  System.out.println("MyCMD exit."); System.exit(0); break; 
        			
        case dir:  	strResult=myModel.printDir(); break;
        
        case mkdir:	result=myModel.mkDir(); break;

        case del:   result=myModel.del(); break;

        case copy:  result=myModel.copy(); break;

        case move:  result=myModel.move(); break;

        case find:  strResult=myModel.find(); break;
					 
        case tree:	strResult=myModel.tree(); break;
  
        case cd:	dir=myModel.cd(); myModel.dir=dir; break;

        default:    System.out.println("Unknown command.");	break;
    }
}
		catch(IllegalArgumentException e){
			System.out.println("Unknown command.");
		}
	return strResult;
}

public static class Command {
	public enum Commands {
	    dir,copy,move,del,tree,cd,exit,find,mkdir
	}
	public static Commands myCommand;  
  }

}
